# -- coding cp949 --
#-*- encoding: utf-8 -*-
from PyQt4 import QtCore , QtGui , uic
from lib.papyDBTable import *
from lib.itemModel import treeItem, PSSdata
from lib.customUI import customUI
import PM_PSStree
import PM_dashBoard
import PM_taskBoard

class projectManager( customUI ):
    def __init__(self , parent = None ):
        QtGui.QMainWindow.__init__(self,parent)
        customUI.__init__(self)         
        self.PSStree = PM_PSStree.PSStree(  )
        self.dashBoard = PM_dashBoard.dashBoard(  )
        self.taskBoard = PM_taskBoard.taskBoard(  )   
        self.setUI()
        self.connections()
#        self.PSSdata = PSSdata()        
        
    def connections(self):
        self.connect(self.PSStree.pssTree.selectionModel() , QtCore.SIGNAL('selectionChanged(QItemSelection, QItemSelection)'), 
                     self.selectionEvent )
    
    def refreshTaskBoard(self):
        if not PSSdata['shotID'] or not PSSdata['seqID'] or not PSSdata['prjID'] : return        
        self.animInfo = JOB_INFO.searches( 'status' , 'startDate' , 'endDate' , 'description'  )        
        self.fxInfo = JOB_INFO.searches( 'status' , 'startDate' , 'endDate' , 'description'  )
        self.mpInfo = JOB_INFO.searches( 'status' , 'startDate' , 'endDate' , 'description'  )
        self.trInfo = JOB_INFO.searches( 'status' , 'startDate' , 'endDate' , 'description'  )
        self.rdInfo = JOB_INFO.searches( 'status' , 'startDate' , 'endDate' , 'description'  )    
        
    def selectionEvent(self):
        self.PSSdata = self.PSStree.PSSdata
        self.dashBoard.refreshBoard( self.PSSdata )
        self.taskBoard.refreshBoard( self.PSSdata )
#        print self.PSSdata
        return self.PSSdata

    def setUI(self):
        self.mainWidget = QtGui.QWidget( )
        
        self.PSStree.setParent( self.mainWidget )

        self.taskWidget = QtGui.QWidget( )
        self.taskWidget_layout = QtGui.QGridLayout( self.taskWidget ) 
        self.taskWidget_layout.addWidget( self.taskBoard )
        self.taskBoard.setParent( self.taskWidget )
                
        self.assetWidget = QtGui.QWidget( )
        self.assetWidget_layout = QtGui.QGridLayout( self.assetWidget )
        self.assetWidget_layout.addWidget( self.dashBoard )
                 
        self.tabWidget = QtGui.QTabWidget( self )        
        self.tabWidget.addTab( self.taskWidget , QtCore.QString( 'TASK') )
        self.tabWidget.addTab( self.assetWidget , QtCore.QString( 'ASSET') )
        
        self.dashBoard.setParent( self.assetWidget )
        
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(2)
        self.PSStree.setSizePolicy(sizePolicy)
        sizePolicy.setHorizontalStretch(8)
        self.tabWidget.setSizePolicy(sizePolicy)
        
        glayout = QtGui.QGridLayout( self.mainWidget )
        glayout.addWidget( self.PSStree , 0 , 0 , 1 , 1 )
        glayout.addWidget( self.tabWidget , 0 , 1 , 1 , 1 )
        self.setCentralWidget( self.mainWidget )
        self.resize( 800 , 410 )         
        self.show()
        
if __name__ == '__main__':
    import sys    
    app = QtGui.QApplication(sys.argv)       
    projectManager = projectManager()    
    app.exec_()   
    
    
    